package org.example;

import java.util.Stack;

public class MyQueue1 {

    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue1() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }
    //一个栈当作入队列，一个栈当作出队列
    //
    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if (!s2.isEmpty()) {
            return s2.pop();
        }else {
            while (!s1.isEmpty()) {
                int val = s1.pop();
                s2.push(val);
            }
            return s2.pop();
        }
    }

    public int peek() {
        if (!s2.isEmpty()) {
            return s2.peek();
        }else {
            while (!s1.isEmpty()) {
                int val = s1.pop();
                s2.push(val);
            }
            return s2.peek();
        }
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }
}
